<?php
	include 'redirectUser.php';
//////////////////////////////////////
	$servicePerPage = 10;
	$user = $_SESSION['curUser'];
//////////////////////////////////////

	$serviceControls = new ServiceSearchControls();
	$serviceControls->setActive(true);
	
	$services = ServiceUtils::find($serviceControls);
	
	//////////////////////////////////////
	$page = null;
	if(! (($page = ParamUtils::get("paginator")) != null && VariableUtils::isNumber($page))){
		$page = 1;		 
	}
	
	$sid = null;
	if(ParamUtils::get("action") != null && ($sid = ParamUtils::get("sid")) != null){
		$serviceToBuy = ServiceUtils::get($sid);
		if($serviceToBuy != null){
			echo "Kupiono nowy serwis o id: " .  UserServiceUtils::buy($serviceToBuy, $user) . "";
		}
	}
?>

<div style="position: absolute; left: 219px; top: 40px;">

<table>

	<tr><th>Nazwa</th><th>Opis</th><th>&nbsp;</th></tr>
	<?php 
		for($i = (($page - 1) * $servicePerPage) ; ($i < $page * $servicePerPage) && $i < sizeof($services);$i++){
			$service = $services[$i];
			echo "<tr> 
						<td>
						" . $service->getName() . 
						"
						</td>
						<td>
						" .  $service->getDesc() . 
						"
						</td>
						<td>
							<a href='bookmarks.php?page=service&action=buy&sid=".$service->getId()."'>Kup </a>						
						</td>
			
				 </tr>";
		}
		
		$pages = ceil(sizeof($services) / $servicePerPage);
		if($pages > 1){
			echo "<tr><td colspan='3'>";
			for($i = 1 ; $i <= $pages ; $i++){
				echo "<a href='bookmarks.php?page=service&paginator=$i'> |$i| </a>";	
			}
			echo "</td></tr>";
		}
	?>	


</table>
</div>